package pers.qianyu.month_202012.date_20201228;

import java.util.*;

/**
 * 9. 分组背包问题
 * https://www.acwing.com/problem/content/9/
 *
 * @author mizzle rain
 * @date 2020-12-28 20:29
 */
public class BagGroup {
    private int N;
    private int V;
    private ArrayList<List<Good>> groups = new ArrayList<>();

    private static class Good {
        int volume;
        int value;

        Good(int volume, int value) {
            this.volume = volume;
            this.value = value;
        }
    }

    private void input() {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.nextLine().split(" ");
        N = Integer.parseInt(s[0]);
        V = Integer.parseInt(s[1]);
        for (int a = 0; a < N; a++) {
            int count = sc.nextInt();
            List<Good> goods = new ArrayList<>();
            for (int i = 0; i < count; i++) {
                int volume = sc.nextInt();
                int value = sc.nextInt();
                goods.add(new Good(volume, value));
            }
            groups.add(goods);
        }
        sc.close();
    }

    private int solve() {
        int[] dp = new int[V + 1];
        for (List<Good> group : groups) {
            for (int i = V; i >= 0; i--) {
                for (Good good : group) {
                    if (i >= good.volume) {
                        dp[i] = Math.max(dp[i], dp[i - good.volume] + good.value);
                    }
                }
            }
        }
        return dp[V];
    }

    public static void main(String[] args) {
        BagGroup main = new BagGroup();
        main.input();
        int res = main.solve();
        System.out.println(res);
    }
}
